#!/bin/bash
#计数请求失败主机
# 设置各主机访问次数变量
c_s=`cat /var/log/secure | awk '/(Failed)/' | awk --re-interval '{match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/,a); print a[0]}' | sort | uniq -c | sort -nr | awk -F" " '{print "主机：",$2,"访问次数："$1}' OFS="---->"`

z_dcs=`cat /var/log/secure | awk '/(Failed)/' | awk --re-interval '{match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/,a); print a[0]}' | sort | uniq -c | sort -nr | head -1 | awk -F " " '{print $1}'`

z_dcszj=`cat /var/log/secure | awk '/(Failed)/' | awk --re-interval '{match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/,a); print a[0]}' | sort | uniq -c | sort -nr | head -1 | awk -F " " '{print $2}'`

counts=`cat /var/log/secure | awk '/(Failed)/' | awk --re-interval '{match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/,a); print a[0]}' | sort | uniq -c | sort -nr | wc -l`

z_fwl=`cat /var/log/secure | awk '/(Failed)/' | awk --re-interval '{match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/,a); print a[0]}' | wc -l`
# 遍历回显
for C_S in ${c_s}
do
  echo ${C_S}
done
echo "=================================================================>"
echo "主机访问总台数：${counts}---->总访问量：${z_fwl}
最大访问主机：${z_dcszj}---->共访问：${z_dcs}"

